#include <cstdio>
#include <cstdint>
#include <cstdlib>

#define fmax(a, b) ((a) > (b) ? (a) : (b))
#define fmin(a, b) ((a) < (b) ? (a) : (b))
#define abs(a) ((a) < 0 ? -(a) : (a))

int main()
{
    uint32_t height = 960;
    uint32_t count = 0;

    auto drawOneLine = [&](uint32_t index, uint32_t color) {
        // auto lineAddr = addr + index * width;
        // for (uint32_t i = 0; i < width; i++) {
        //     lineAddr[i] = color;
        // }
        printf("%u %x\n", index, color);
    };
    const auto heightdiv6 = height / 6;
    auto selectColor = [&](int32_t index) {
        auto func = [&](int32_t x) {
            int32_t h = height;
            x = ((x % h) + h) % h;
            auto ret = 3.0 - x * 1.0 / heightdiv6;
            ret = abs(ret) - 1.0;
            ret = fmax(ret, 0.0);
            ret = fmin(ret, 1.0);
            return uint32_t(ret * 0xff);
        };
        return 0xff000000 + func(index) +
            (func(index - 2 * heightdiv6) << 8) + (func(index + 2 * heightdiv6) << 16);
    };

    constexpr uint32_t framerate = 100;
    count = ((count % framerate) + framerate) % framerate;
    uint32_t offset = count * height / framerate;
    for (uint32_t i = 0; i < height; i++) {
        auto color = selectColor(offset + i);
        drawOneLine(i, color);
    }
    return 0;
}
